package dongshi.daddy.proxy;

import dongshi.daddy.proxy.v1.cjlib.Frank;
import dongshi.daddy.proxy.v1.dynamic.CuiHuaNiu;
import dongshi.daddy.proxy.v1.statics.ILawSuit;
import dongshi.daddy.proxy.v1.statics.ProxyFactory;
import dongshi.daddy.proxy.v2.AnimalService;
import dongshi.daddy.proxy.v2.AnimalServiceImpl;
import dongshi.daddy.proxy.v2.PersonService;
import dongshi.daddy.proxy.v2.PersonServiceImpl;
import dongshi.daddy.proxy.v2.cjlib.CjlibProxyFactory;
import dongshi.daddy.proxy.v2.common.Transaction;
import dongshi.daddy.proxy.v2.jdkproxy.ServiceProxyFactory;
import dongshi.daddy.proxy.v2.statics.AnimalServiceProxy;
import dongshi.daddy.proxy.v2.statics.PersonServiceProxy;
import org.junit.Test;

public class ProxyTest {
    @Test
    public void staticTest() {
        ProxyFactory.getProxy().submit("工资流水在此");
        ProxyFactory.getProxy().defend();
    }

    @Test
    public void testDynamic() {
        ILawSuit proxy= (ILawSuit) dongshi.daddy.proxy.v1.dynamic.ProxyFactory.getDynProxy(new CuiHuaNiu());
        proxy.submit("工资流水在此");
        proxy.defend();
    }

    @Test
    public void testCjlib() {
        Frank cProxy = (Frank) dongshi.daddy.proxy.v1.cjlib.ProxyFactory.getGcLibDynProxy(new Frank());
        cProxy.submit("工资流水在此");
        cProxy.defend();
    }

    @Test
    public void serviceStatic() {
        new PersonServiceProxy(new PersonServiceImpl(), new Transaction()).savePerson();

        new AnimalServiceProxy(new AnimalServiceImpl(), new Transaction()).saveAnimal();
    }

     @Test
    public void serviceJdkProxy() {
         ((PersonService) ServiceProxyFactory.makeProxy(new PersonServiceImpl())).savePerson();

         ((AnimalService) ServiceProxyFactory.makeProxy(new AnimalServiceImpl())).saveAnimal();
    }


     @Test
    public void serviceCjlibProxy() {
         ((PersonServiceImpl) CjlibProxyFactory.getGcLibDynProxy(new PersonServiceImpl())).savePerson();

         ((AnimalServiceImpl) CjlibProxyFactory.getGcLibDynProxy(new AnimalServiceImpl())).saveAnimal();
    }

}
